package com.jason.schedulemigrationtest.controller;

import com.jason.schedulemigrationtest.po.MigrationArchiveLog;
import com.jason.schedulemigrationtest.service.MigrationArchiveLogService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/migration/logs")
public class MigrationLogController {

    @Resource
    private MigrationArchiveLogService migrationArchiveLogService;

    /**
     * 批次号查询迁移日志
     * @param batchId
     * @return
     */
    @GetMapping("/by-batchId")
    public MigrationArchiveLog getByBatchId(@RequestParam String batchId) {
        return migrationArchiveLogService.getByBatchId(batchId);
    }

    /**
     * 获取最近的n条迁移日志
     */
    @GetMapping("/recent")
    public List<MigrationArchiveLog> getRecentLogs(@RequestParam(defaultValue = "10") int limit) {
        return migrationArchiveLogService.getRecentLogs(limit);
    }

    /**
     * 获取所有回滚的迁移日志
     */
    @GetMapping("/rollback")
    public List<MigrationArchiveLog> getRollbackLogs() {
        return migrationArchiveLogService.getRollbackLogs();
    }

    /**
     * 根据日期范围查询归档日志 日期格式 yyyy-MM-dd
     * @return 归档日志列表
     */
    @GetMapping("/by-date")
    public List<MigrationArchiveLog> getByDate(@RequestParam String startDate,
                                             @RequestParam String endDate) {
        return migrationArchiveLogService.getByDate(startDate, endDate);
    }
}